import cv2
img = cv2.imread('1.jpg')
print(img.shape)
print('图片本身=', img)
## 切割图像  其实就是三维数组的切分
# cat = img[0:500, 0:400]
# cv2.imshow('cat', cat)
# cv2.waitKey(0)
## 直接提取颜色值
# b,g,r = cv2.split(img)
# print('b===========', b)
# print('g===========', g)
# print('r===========', r)
## 提取出的bgr可以再组合起来
# newImg = cv2.merge((b, g, r))
# print(newImg.shape)
# cv2.imshow('newImg', newImg)
# cv2.waitKey(0)

## 把图片的b,g都改成0 只保留r
copy_img2 = img.copy()
copy_img2[:,:,0] = 0
copy_img2[:,:,1] = 0
print("修改后的图片",copy_img2)
cv2.imshow('r', copy_img2)
cv2.waitKey(0)